<template>
  <div class="MyUserInfo">
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>个人信息卡</span>
          <el-button type="text">修改</el-button>
        </div>
      </template>
      <div class="text item">
        <img :src="userDetail.avatarUrl ? userDetail.avatarUrl : '@/assets/userInfo.png'" alt="" />
        <div class="username">{{ userDetail.userName }}</div>
        <div class="remark">这个家伙很懒，什么都没有留下</div>
      </div>
      <ul class="detail">
        <li>
          <el-icon>
            <User />
          </el-icon>
          <span class="remark_value">{{ userDetail.userName }}</span>
        </li>
        <li>
          <el-icon>
            <House />
          </el-icon>
          <span class="remark_value">{{ userDetail.email }}</span>
        </li>
        <li>
          <el-icon>
            <Bell />
          </el-icon>
          <span class="remark_value">{{ userDetail.roleType == 0 ? '管理员' : userDetail.roleType == 1 ? '老师' : '学生'
            }}</span>
        </li>
        <li>
          <el-icon>
            <Iphone />
          </el-icon>
          <span class="remark_value" style="color: blur">{{ userDetail.phone }}</span>
        </li>
        <li>
          <el-icon>
            <OfficeBuilding />
          </el-icon>
          <span class="remark_value">{{ userDetail.gender == 0 ? '男' : '女' }}</span>
        </li>
      </ul>
    </el-card>
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>账号信息卡</span>
          <el-button type="text" @click="handleEdit">修改</el-button>
        </div>
      </template>
      <div class="Information_card">
        <div class="info_item">
          <div class="top_item">账号/手机号</div>
          <div class="main_item">已绑定手机号：{{ userDetail.phone }}</div>
        </div>

        <div class="info_item">
          <div class="top_item">密码</div>
          <div class="main_item">已加密密码：*************</div>
        </div>
        <div class="info_item">
          <div class="top_item">邮箱</div>
          <div class="main_item">已绑定邮箱：{{ userDetail.email }}</div>
        </div>
      </div>
    </el-card>
    <MyuserListDia title="修改信息" v-model:queryCount="queryCount" v-model:editItem="editItem" />
  </div>
</template>

<script setup>
import useUserInfo from "store/useUserInfo.js";
const useUserInfoStore = useUserInfo();
import { storeToRefs } from "pinia";
const { userDetail } = storeToRefs(useUserInfoStore);
import MyuserListDia from "./dialog/MyuserListDia.vue";
import { ref, onMounted, provide, watch } from "vue";
import { getUserInfoByIdApi } from "@/api/index";

const queryCount = ref(1);
watch(queryCount, async () => {
  const getUserInfo = await getUserInfoByIdApi(userinfo.userId);
  console.log(getUserInfo, "getUserInfo");
  userDetail.value = getUserInfo.data
  sessionStorage.setItem("userDetail", JSON.stringify(getUserInfo.data));
});
// 弹窗
const show = ref(false);
// 注入依赖
provide("SHOW", show);
const editItem = ref({});
// 编辑
const handleEdit = () => {
  editItem.value = userDetail.value;
  show.value = true;
}

onMounted(() => {
  console.log(userDetail.value);
});

</script>
<style scoped lang="scss">
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.text {
  font-size: 14px;
}

.box-card {
  width: 100%;

  .item {
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;

    img {
      width: 120px;
      height: 120px;
      border-radius: 10px;
      overflow: hidden;
    }

    .username {
      font-size: 20px;
      font-weight: 600;
      margin-top: 10px;
      font-family: "Helvetica Neue", Helvetica, "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", 微软雅黑, Arial, sans-serif;
    }

    .remark {
      max-width: 200px;
      text-align: center;
      margin: 8px 0;
      color: #6b7280;
    }
  }

  .detail {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;

    li {
      width: 210px;
      //超出省略
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      padding: 10px 0;
      font-size: 16px;
      font-family: "Helvetica Neue", Helvetica, "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", 微软雅黑, Arial, sans-serif;
      display: flex;
      align-items: center;
      justify-content: center;

      .remark_value {
        flex: 1;
        margin-left: 8px;
      }
    }
  }

  .Information_card {
    .info_item {
      border-top: 1px solid #f0f0f0;
      border-bottom: 1px solid #f0f0f0;
      padding: 15px 0;

      .top_item {
        font-size: 18px;
        color: #4b5563;
        margin-bottom: 10px;
      }

      .main_item {
        font-size: 14px;
        color: #9ca3af;
      }
    }
  }
}

.MyUserInfo {
  display: grid;
  grid-template-columns: 1fr 2fr;
  grid-template-rows: auto;
  grid-gap: 10px;
}
</style>
